home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
500 MB Nyheder Direkte fra Internet 2
/
500 MB nyheder direkte fra internet CD 2.iso
/
start
/
data
/
text
/
pretty.txt
< prev
next >
Wrap
Text File
|
1994-09-21
|
32KB
|
786 lines
ZONES
The leftmost part of the screen is called the first zone. To
the right of that zone lies the second zone.
If your computer's fancy, it also has a third, fourth, and
fifth zone; and each zone 16 characters wide, so the entire
screen is 80 characters wide.
(If your computer's not so fancy, it might have fewer zones, or
the zones might be narrower; and the screen might be less than 80
characters wide. To find out about your computer's peculiarities,
read the ``Versions of BASIC'' appendix.)
A comma makes the computer jump to a new zone. Here's an
example:
PRINT "SIN","KING"
The computer will print SIN and KING on the same line; but
because of the comma before KING, the computer will print KING in
the second zone, like this:
SIN KING
first zone second zone third zone fourth zone
fifth zone
To turn that example into a program, put a number in front of
the line, like this:
10 PRINT "SIN","KING"
When you type RUN, the computer will print:
SIN KING
This program does the same thing:
10 PRINT "SIN",
20 PRINT "KING"
Line 10 makes the computer print SIN and then jump to the next
zone. Line 20 makes the computer print KING. The computer will
print:
SIN KING
This example's silly:
PRINT "LOVE","CRIES","OUT"
The computer will print LOVE in the first zone, CRIES in the
second zone, and OUT in the third zone, like this:
LOVE CRIES OUT
This example's even sillier:
PRINT "LOVE","CRIES","OUT","TO","ME","AT","NIGHT"
The computer will print LOVE in the first zone, CRIES in the
second, OUT in the third, TO in the fourth, ME in the fifth, and
the remaining words below, like this:
LOVE CRIES OUT TO
ME
AT NIGHT
This example tells a bad joke:
PRINT "I THINK YOU ARE UGLY","I'M JOKING"
The computer will print I THINK YOU ARE UGLY, then jump to a new
zone, then print I'M JOKING, like this:
I THINK YOU ARE UGLY I'M JOKING
first zone second zone third zone fourth zone
fifth zone
When you combine commas with semicolons, you can get weird
results:
PRINT "EAT","ME";"AT";"BALLS","NO";"W"
That line contains commas and semicolons. A comma makes the
computer jump to a new zone, but a semicolon does not make the
computer jump. The computer will print EAT, then jump to a new
zone, then print ME and AT and BALLS, then jump to a new zone,
then print NO and W. Altogether, the computer will print:
EAT MEATBALLS NOW
Skipping a zone
You can make the computer skip over a zone:
PRINT "JOE"," ","LOVES SUE"
The computer will print JOE in the first zone, a blank space in
the second zone, and LOVES SUE in the third zone, like this:
JOE LOVES SUE
first zone second zone third zone fourth zone
fifth zone
You can type that example even more briefly, like this:
PRINT "JOE",,"LOVES SUE"
Loops
This program makes the computer greet you:
10 PRINT "HI",
20 GO TO 10
The computer will print HI many times. Each time will be in a
new zone, like this:
HI HI HI HI
HI
HI HI HI HI
HI
HI HI HI HI
HI
etc.
Tables
This program prints a list of words and their opposites:
10 PRINT "GOOD","BAD"
20 PRINT "BLACK","WHITE"
30 PRINT "GRANDPARENT","GRANDCHILD"
40 PRINT "HE","SHE"
Line 10 makes the computer print GOOD, then jump to the next
zone, then print BAD. Altogether, the computer will print:
GOOD BAD
BLACK WHITE
GRANDPARENT GRANDCHILD
HE SHE
The first zone contains a column of words; the second zone
contains the opposites. Altogether, the computer's printing looks
like a table. So whenever you want to make a table, use zones, by
putting commas in your program.
Let's make the computer print this table:
NUMBER SQUARE
3 9
4 16
5 25
6 36
7 49
8 64
9 81
10 100
Here's the program:
10 PRINT "NUMBER","SQUARE"
20 FOR I = 3 TO 10
30 PRINT I,I*I
40 NEXT
Line 10 prints the word NUMBER at the top of the first column,
and the word SQUARE at the top of the second. Line 20 says I goes
from 3 to 10; to begin, I is 3. Line 30 makes the computer print:
3 9
Line 40 makes the computer do the same thing for the next I, and
for the next I, and for the next; so the computer prints the
whole table.
TAB
When the computer puts a line of information on your screen,
the leftmost character in the line is said to be at position 1.
The second character in the line is said to be at position 2.
This command makes the computer skip to position 6 and then
print ``HOT'':
PRINT TAB(6)"HOT"
The computer will print:
HOT
12345678
Here's a fancier example:
PRINT TAB(6)"HOT";TAB(13)"BUNS"
The computer will skip to the 6th position, then print ``HOT'',
then skip to the 13th position, then print ``BUNS'':
HOT BUNS
12345678 13
Diagonal
This program prints a diagonal line:
10 FOR I = 1 TO 12
20 PRINT TAB(I)"*"
30 NEXT
Line 10 says to do the loop twelve times, so the computer does
line 20 repeatedly. The first time the computer does line 20, the
I is 1, so the computer prints an asterisk at position 1:
*
The next time, the I is 2, so the computer skips to position 2
and prints an asterisk:
*
The next time, the I is 3, so the computer skips to position 3
and prints an asterisk:
*
Altogether, the program makes the computer print this picture:
*
*
*
*
*
*
*
*
*
*
*
*
Calendar
Let's make the computer print a
calendar for the whole year. We must begin by telling the
computer how many days are in each month:
Month's name Month's length
January 31
February 28 or 29
March 31
April 30
May 31
June 30
July 31
August 31
September 30
October 31
November 30
December 31
That list becomes our data:
10 DATA JANUARY,31,FEBRUARY,28,MARCH,31,APRIL,30
20 DATA MAY,31,JUNE,30,JULY,31,AUGUST,31
30 DATA SEPTEMBER,30,OCTOBER,31,NOVEMBER,30,DECEMBER,31
(For a leap year, change line 10.)
To make the computer look at that
data, tell the computer to READ:
40 READ N$,L
That makes the computer read a month's Name and Length.
To read all the data, the computer
should do line 40 twelve times. So put line 40 inside a loop,
like this:
English BASIC
Here are the months 10 DATA
JANUARY,31,FEBRUARY,28,MARCH,31,APRIL,30
and their lengths. 20 DATA
MAY,31,JUNE,30,JULY,31,AUGUST,31
30 DATA
SEPTEMBER,30,OCTOBER,31,NOVEMBER,30,DECEMBER,31
For each month, 39 FOR M = 1 TO 12
read its Name & Length, 40 READ N$,L
print its Name, 50 PRINT N$
print all its days, 60 FOR D = 1 TO L
70 PRINT D;
80 NEXT
and press the ENTER key 90 PRINT
twice at end of the month. 91 PRINT
100 NEXT
When you run that program, the
computer prints a calendar beginning like this:
JANUARY
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20
21 22 23 24 25 26 27 28 29 30 31
FEBRUARY
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20
21 22 23 24 25 26 27 28
MARCH
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20
21 22 23 24 25 26 27 28 29 30 31
Pretty weeks Although that program
makes the computer print the right numbers for each month, it
prints the numbers in the wrong places. Let's make the computer
print at most 7 numbers in each row, so each is a week.
To print the numbers in the right
places, use TAB:
70 PRINT TAB(T)D;
Line 70 will make the computer print each day in the right
position . . . if we define T correctly. But how should we define
T?
For Sunday, let's make T be 2, so
that Sunday begins at position 2. For Monday, let's make T be 6,
so that Monday begins at position 6. For Tuesday, let's make T be
10; for Wednesday, 14; Thursday, 18; Friday, 22; and Saturday,
26. So whenever a day's been printed, T should normally increase
by 4 for the next day:
71 T=T+4
Saturday's the last day of the week; after Saturday, we must
begin a new week. So if T has passed Saturday (which is 26), we
want T to become 2 (for Sunday); and if there are more days left
in the month, we want the computer to press the ENTER key (to
start a new week):
72 IF T>26 THEN T=2: IF D<L THEN PRINT
Which year would you like a calendar for: 1993? 1994? 1995?
This program makes a pretty calendar for 1993:
1 PRINT "CALENDAR FOR 1993"
2 PRINT
3 T=22
10 DATA JANUARY,31,FEBRUARY,28,MARCH,31,APRIL,30
20 DATA MAY,31,JUNE,30,JULY,31,AUGUST,31
30 DATA SEPTEMBER,30,OCTOBER,31,NOVEMBER,30,DECEMBER,31
39 FOR M = 1 TO 12
40 READ N$,L
50 PRINT N$
51 PRINT " SUN MON TUE WED THU FRI SAT"
60 FOR D = 1 TO L
70 PRINT TAB(T)D;
71 T=T+4
72 IF T>26 THEN T=2: IF D<L THEN PRINT
80 NEXT
90 PRINT
91 PRINT
100 NEXT
Line 1 prints the heading. Line 2 puts a blank line underneath
the heading. Since 1993 begins on a Friday, line 3 tells the
computer to start T at 22 (which is the position for Friday).
Line 51 prints the heading for each month; when you type that
line, put 2 blank spaces before SUN.
The computer will print a calendar beginning like this:
CALENDAR FOR 1993
JANUARY
SUN MON TUE WED THU FRI SAT
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
FEBRUARY
SUN MON TUE WED THU FRI SAT
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28
MARCH
SUN MON TUE WED THU FRI SAT
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Variations If you want a different year, change lines 1 and 3.
For a leap year, change line 10.
If you want the calendar to be taller, insert extra blank
lines. To do that, replace ``PRINT'' by ``PRINT: PRINT: PRINT''
in lines 2, 72, 90, and 91:
2 PRINT: PRINT: PRINT
72 IF T>26 THEN T=2: IF D<L THEN PRINT: PRINT: PRINT
90 PRINT: PRINT: PRINT
91 PRINT: PRINT: PRINT
If you want the calendar to look wider (or narrower), change
the positions for Sunday, Monday, Tuesday, etc, by changing the T
numbers (in lines 3, 51, 71, and 72).
LOCATE
The computer makes the
screen show several lines of information. On the screen, the top
line is called line 1; underneath it is line 2; then comes line
3; etc.
Each line consists of
many characters. The leftmost character is at position 1; the
next character is at position 2; etc.
On the screen, the
computer will print wherever you wish.
For example, to make the
computer print the word DROWN so that DROWN begins at line 3's
7th position, type this:
LOCATE 3,7: PRINT "DROWN"
The computer will print the word's first letter (D) at line 3's
7th position. The computer will print the rest of the word
afterwards.
You'll see the first
letter (D) at line 3's 7th position, the next letter (R) at the
next position (line 3's 8th position), the next letter (O) at the
next position (line 3's 9th position), etc.
Your computer
Most computers
understand the word LOCATE, but your computer might be different.
To find out about your computer, check the ``Versions of BASIC''
appendix.
PIXELS
The image on the computer's screen is called the picture. If
you stare at the picture closely, you'll see the picture's
composed of thousands of tiny rectangles. Each tiny rectangle is
called a picture's element, or pic's el, or pixel, or pel.
Coordinates
The tiny rectangle in the screen's upper-left corner is called
pixel (0,0); just to the right of it is pixel (1,0); then comes
pixel (2,0); etc. Underneath pixel (0,0) is pixel (0,1). Here are
the positions of the pixels:
pixel (0,0) pixel (1,0) pixel (2,0) pixel (3,0) pixel
(4,0) etc.
pixel (0,1) pixel (1,1) pixel (2,1) pixel (3,1) pixel
(4,1) etc.
pixel (0,2) pixel (1,2) pixel (2,2) pixel (3,2) pixel
(4,2) etc.
pixel (0,3) pixel (1,3) pixel (2,3) pixel (3,3) pixel
(4,3) etc.
Each pixel's name consists of two numbers in parentheses. The
first number's called the X coordinate; the second number's
called the Y coordinate. For example, if you're talking about
pixel (4,3) its X coordinate is 4, and its Y coordinate is 3.
The X coordinate tells how far to the right the pixel is. The Y
coordinate tells how far down. So pixel (4,3) is the pixel that's
4 to the right and 3 down.
On the computer, the Y coordinate measures how far down, not
up! If you've had the misfortune of reading old-fashioned math
books in which the Y coordinate measured how far up, you'll have
to reverse your thinking!
How many pixels?
How many pixels are on the screen? The answer depends on which
computer you have.
If your computer's typical, the X coordinate goes from 0 to
319, and the Y coordinate goes from 0 to 199. So on a typical
computer, the pixel at the screen's lower right-hand corner is
pixel (319,199); and the total number of pixels on the screen is
``320 times 200'' which is 64 thousand.
But your computer might not be ``typical''. Check the
``Versions of BASIC'' appendix.
Fundamental shapes
The computer can draw three fundamental shapes: dots, lines,
and circles.
To make the computer draw a dot at pixel (100,100), say:
PLOT (100,100)
Though some computers understand the word PLOT, other computers
require a different word instead, such as ``DRAW'' or ``PSET''.
To find out which word your computer understands, check the
``Versions of BASIC'' appendix. For example, the appendix says
that if you have an IBM PC or clone, you must say ``PSET''
instead of ``PLOT''. The appendix also says that if you have an
IBM PC or clone, you must give a command such as ``SCREEN 1''
before giving any graphics commands, so begin like this:
SCREEN 1
PSET (100,100)
To make the computer
draw a line from pixel (0,0) to pixel (100,100), say:
LINE (0,0)-(100,100)
To make the computer
draw a line from pixel (0,0) to pixel (100,100), and then draw a
line from that pixel (100,100) to pixel (70,120), say:
LINE (0,0)-(100,100)
LINE -(70,120)
To make the computer
draw a circle whose center is pixel (100,100) and whose radius is
50, say:
CIRCLE (100,100),50
The computer draws each
shape in white, on a black background.
PAINT
After you've drawn an
outline of a shape (by using dots, lines, and circles), you can
fill in the middle of the shape, by telling the computer to PAINT
the shape.
Here's how to PAINT a
shape that you've drawn (such as a circle or a house). Find a
pixel that's in the middle of the shape and that's still black;
then tell the computer to PAINT, starting at that pixel. For
example, if pixel (100,101) is inside the shape and is still
black, say:
PAINT (100,101)
Colors
You can use these
colors:
0. black 8. light
black (gray)
1. blue 9. light
blue
2. green 10. light
green
3. cyan (greenish blue) 11. light
cyan (aqua)
4. red 12. light
red (pink)
5. magenta (purplish red) 13. light
magenta
6. brown 14. light
brown (yellow)
7. cream (yellowish white) 15. light
cream (pure white)
Normally, the PLOT,
LINE, CIRCLE, and PAINT commands draw in yellowish white (cream).
If you prefer a different color, put a comma and the color's
number at the end of the command. For example, if you want to
draw a line from (0,0) to (100,0) in green (whose color number is
2), type this:
LINE (0,0)-(100,0),2
When you give a PAINT
command, you must make its color the same as the color of the
outline you're filling in.
If your screen is a TV
or composite monitor (instead of an RGB monitor) or your computer
is obsolescent (such as an Apple 2), you'll get the correct
colors only when you draw horizontal lines and adjust the COLOR
and TINT dials. When you draw vertical lines or diagonals or
circles or dots, the colors will be slightly off.
Boxes
If you type ___
LINE (0,0)-(100,100),2
the computer draws a line from pixel (0,0) to (100,100) using
color 2.
If you put the letter B at the end of the LINE command, like
this ___
LINE (0,0)-(100,100),2,B
the computer will draw a box instead of a line. One corner of the
box will be at pixel (0,0); the opposite corner will be at
(100,100); and the box will be drawn using color 2.
If you put BF at the end of the LINE command, like this ___
LINE (0,0)-(100,100),2,BF
the computer will draw a box and also fill it in, by painting its
interior.
SOUNDS
To produce sounds, you can say BEEP,
SOUND, or PLAY. BEEP appeals to business executives; SOUND
appeals to doctors and engineers; and PLAY appeals to musicians.
I'll explain how the typical
computer handles the words BEEP, SOUND, and PLAY; but check the
``Versions of BASIC'' appendix to find out whether your computer
handles them differently.
BEEP
If you type ___
BEEP
the typical computer will beep. Specifically, it will play a note
whose frequency (``pitch'') is 800 hertz, and it will play the
note for a quarter of a second.
You can say BEEP in the middle of
your program. For example, you can tell the computer to BEEP if a
person enters wrong data.
Computerized weddings This program
makes the computer act as a priest and perform a marriage
ceremony:
10 INPUT "DO YOU TAKE THIS WOMAN TO BE YOUR LAWFUL WEDDED
WIFE";A$
20 IF A$<>"I DO" THEN BEEP: PRINT "TRY AGAIN!": GO TO 10
30 INPUT "DO YOU TAKE THIS MAN TO BE YOUR LAWFUL WEDDED
HUSBAND";A$
40 IF A$<>"I DO" THEN BEEP: PRINT "TRY AGAIN!": GO TO 30
50 PRINT "I NOW PRONOUNCE YOU HUSBAND AND WIFE."
Line 10 makes the computer ask the
groom, ``DO YOU TAKE THIS WOMAN TO BE YOUR LAWFUL WEDDED WIFE?''
If the groom doesn't say ``I DO'', line 20 makes the computer
beep, say ``TRY AGAIN!'', and repeat the question. Lines 30 and
40 do the same thing to the bride. Line 50 congratulates the
couple for having answered correctly.
SOUND
If you type ___
SOUND 440,18.2
the typical computer will produce a sound. In that command, the
440 is the frequency (``pitch''), measured in hertz (cycles per
second); so the sound will be a musical note whose pitch is 440
hertz. (That note happens to be ``the A above middle C'').
If you replace the 440 by a higher
number, the sound will have a higher pitch.
When you were a baby, you could
probably hear up to 20000. As you get older, your hearing gets
worse, and you can't hear such high notes. Today, the highest
sound you can hear is probably somewhere around 14000.
To find out, give yourself a hearing
test, by running this program:
10 INPUT "WHAT PITCH WOULD YOU LIKE ME TO PLAY";P
20 SOUND P,18.2
30 GO TO 10
When you run that program, begin by
inputting a low pitch (such as 200). Then input a higher number,
then an even higher number, until you finally pick a number so
high you can't hear it. (When trying that test, put your ear
close to the computer's speaker, which is in the computer's front
left corner.) When you've picked a number too high for you to
hear, try a slightly lower number. Keep trying different numbers,
until you find the highest number you can hear.
Have a contest with your friends:
find out which of your friends can hear best.
If you run that program every year,
you'll see that your hearing gets gradually worse. For example,
when I was 36 years old, the highest pitch I could hear was about
14500, but I can't hear that high anymore. How about you?
In those examples, the 18.2 makes
the computer produce the sound for 1 second. If you want the
sound to last longer ___ so that it lasts 2 seconds ___ replace
the 18.2 by 18.2*2. For 10 seconds, say 18.2*10. (That's because
the computer's metronome beats 18.2 times per second.)
PLAY
If you type ___
PLAY "CDG#B-A"
the typical computer will play the note C, then D, then G sharp,
then B flat, then A.
Octave The computer can play in seven octaves, numbered from 0
to 6. Octave 0 consists of very bass notes; octave 6 consists of
very high-pitched notes. In each octave, the lowest note is a C:
the notes in an octave are C, C#, D, D#, E, F, F#, G, G#, A, A#,
and B.
``Middle C'' is at the beginning of octave 2. Normally, the
computer plays in octave 4. To make the computer switch to octave
3, type the letter ``O'' followed by a 3, like this:
PLAY "O3"
After giving that command, anything else you PLAY will be in
octave 3, until you change octaves again.
Length Besides playing with pitches, you can also play with
rhythms (``lengths'' of the notes). Normally each note is a
``quarter note''. To make the computer switch to eighth notes
(which are faster), type this:
PLAY "L8"
Besides using L8 for eighth notes, you can use L16 for
sixteenth notes (which are even faster), L32 for thirty-second
notes (which are super-fast), and L64 for sixty-fourth notes
(which are super-super-fast). For long notes, you can use L2
(which gives a half note) or L1 (which gives a whole note).
You can use any length from L1 to L64. You can even use
in-between lengths, such as L7 or L23 (though such rhythms are
hard to stamp your foot to).
Dots If you put a period after a note, the computer will
multiply the note's length by 1½.
For example, suppose you say:
PLAY "L8CE.D"
The C will be an 8th note, E will be 1½ times as long as an 8th
note, and D will be an 8th note. Musicians call that E a dotted
eighth note.
If you put two periods after a note (like this: E..), the
computer will multiply the note's length by 13/4. Musicians say
the note is double dotted.
If you put three periods after a note (like this: E...), the
computer will multiply the note's length by 17/8.
Pause To make the computer pause (``rest'') for an eighth note,
put a P8 into the music string.
Tempo Normally, the computer plays 120 quarter notes per
minute; but you can change that tempo. To switch to 150 quarter
notes per minute, say:
PLAY "T150"
You can switch to any tempo from 32 to 255. The 32 is very
slow; 255 is very fast. In musical terms, 40=larghissimo,
50=largo, 63=larghetto, 65=grave, 68=lento, 71=adagio,
76=andantino, 92=andante, 114=moderato, 120=allegretto,
144=allegro, 168=vivace, 188=presto, and 208=prestissimo.
Combine them You can combine all those musical commands into a
single PLAY statement. For example, to set the tempo to 150, the
octave to 3, the length to 8 (which means an eighth note), and
then play C and D, and then change the length to 4 and play E,
type this:
PLAY "T150O3L8CDL4E"
PRINT USING
Suppose you want to add
$12.47 to $1.03. The correct answer is $13.50. This almost works:
PRINT 12.47+1.03
It makes the computer print:
13.5
But instead of 13.5, we should try to make the computer print
13.50.
This command forces the
computer to print 13.50:
PRINT USING "##.##"; 12.47+1.03
The ``##.##'' is called the picture or image or format: it says
to print two characters, then a decimal point, then two digits.
The computer will print:
13.50
This command puts that
answer into a sentence:
PRINT USING "YOU SPENT ##.## AT OUR STORE"; 12.47+1.03
The computer will print:
YOU SPENT 13.50 AT OUR STORE
Rounding
This program makes the
computer divide 300 by 7 but round the answer to two decimal
places:
PRINT USING "##.##"; 300/7
When the computer divides 300 by 7, it gets 42.8571, but the
format rounds the answer to 42.86. The computer will print:
42.86
Multiple numbers
Every format (such as
``###.##'') is a string. You can replace the format by a string
variable:
10 A$="###.##"
20 PRINT USING A$; 247.91
30 PRINT USING A$; 823
40 PRINT USING A$; 7
50 PRINT USING A$; -5
60 PRINT USING A$; -80.3
The computer will print:
247.91
823.00
7.00
-5.00
-80.30
When the computer prints that column of numbers, notice that the
computer prints the decimal points underneath each other so that
they line up. So to make decimal points line up, say PRINT USING
instead of just PRINT.
To print those numbers
across instead of down, say this:
PRINT USING "###.##"; 247.91,823,7,-5,-80.3
It makes the computer print 247.91, then 823.00, etc., like this:
247.91823.00 7.00 -5.00-80.30
Since the computer prints those numbers so close together,
they're hard to read. To make the computer insert extra space
between the numbers, widen the format by putting a fourth ``#''
before the decimal point:
PRINT USING "####.##"; 247.91,823,7,-5,-80.3
Then the computer will print:
247.91 823.00 7.00 -5.00 -80.30
If you say ___
PRINT USING "MY ## PALS DRANK ###.# PINTS OF GIN"; 24,983.5
the computer will print:
MY 24 PALS DRANK 983.5 PINTS OF GIN
Oversized numbers
Suppose you say:
PRINT USING "###.##"; 16238.7
The computer tries to print 16238.7 by using the format
``###.##''. But since that format allows just three digits before
the decimal point, the format isn't large enough to fit 16238.7.
So the computer must disobey the format. But the computer also
prints a percent sign, which means, ``Warning! I am disobeying
you!'' Altogether, the computer prints:
%16238.70
Final semicolon
At the end of the PRINT USING statement, you can put a
semicolon:
10 PRINT USING "##.##"; 13.5;
20 PRINT "CREDIT"
Line 10 makes the computer print 13.50. The semicolon at the
end of line 10 makes the computer print CREDIT on the same line,
like this:
13.50CREDIT
Advanced formats
Suppose you're running a high-risk business. On Monday, your
business runs badly: you lose $27,931.60, so your ``profit'' is
minus $27,931.60. On Tuesday, your business does slightly better
than break-even: your net profit for the day is $8.95.
Let's make the computer print the word PROFIT, then the amount
of your profit (such as -$27,931.60 or $8.95), then the word HA
(because you're cynical about how your business is going).
You can do that printing in several ways. Let's explore them. .
. .
If you say ___
10 A$="PROFIT######.##HA"
20 PRINT USING A$; -27931.6
30 PRINT USING A$; 8.95
the computer will print:
PROFIT-27931.60HA
PROFIT 8.95HA
Comma If you change the format to ``PROFIT###,###.##HA'', the
computer will insert a comma if the number is large:
PROFIT-27,931.60HA
PROFIT 8.95HA
Plus sign If you change the format to ``PROFIT+#####.##HA'',
the computer will print a plus sign in front of any positive
number:
PROFIT-27931.60HA
PROFIT +8.95HA
Trailing minus To print a negative number, the computer
normally prints a minus sign before the number. That's called a
leading minus. You can make the computer put the minus sign after
the number instead; that's called a trailing minus. For example,
if you change the format to ``PROFIT######.##-HA'', the computer
will print a
minus sign after a negative number (and no minus after a positive
number), like this:
PROFIT27931.60-HA
PROFIT 8.95 HA
Dollar sign Normally, a
format begins with ##. If you begin with $$ instead (like this:
``PROFIT$$#####.##HA''), the computer will print a dollar sign
before the digits:
PROFIT-$27931.60HA
PROFIT $8.95HA
Check protection If you
begin with ** (like this: ``PROFIT**#####.##HA''), the computer
will print asterisks before the number:
PROFIT*-27931.60HA
PROFIT******8.95HA
If you begin with **$
(like this: ``PROFIT**$#####.##HA''), the computer will print
asterisks and a dollar sign:
PROFIT*-$27931.60HA
PROFIT******$8.95HA
When you're printing a
paycheck, use the asterisks to prevent the employee from
enlarging his salary. Since the asterisks protect the check from
being altered, they're called check protection.
Combination You can
combine several techniques into a single format. For example, you
can combine the comma, the trailing minus, and the **$ (like
this: ``PROFIT**$##,###.##-HA''), so that the computer will
print:
PROFIT**$27,931.60-HA
PROFIT*******$8.95 HA
E notation If you change
the format to ``PROFIT##.#####^^^^HA'', the computer will print
numbers by using E notation:
PROFIT-2.79316E+04HA
PROFIT 8.95000E+00HA